import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/screenutil.dart';
import 'package:flutter_swiper/flutter_swiper.dart';
import 'package:flutterlogistics/config/gloab_config.dart';
import 'package:flutterlogistics/config/router_config.dart';
import 'package:flutterlogistics/utils/log_util.dart';
import 'package:flutterlogistics/utils/sp_util.dart';

class GuidePage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => GuideState();
}

class GuideState extends State<GuidePage> {
  List<Map> imgList = [
    {"url": "https://www.itying.com/images/flutter/1.png"},
    {"url": "https://www.itying.com/images/flutter/2.png"},
    {"url": "https://www.itying.com/images/flutter/3.png"}
  ];

  var valueChangeIndex = 0;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Stack(
        fit: StackFit.expand,
        children: <Widget>[
          Swiper(
            itemBuilder: (BuildContext context, int index) {
              return new Image.network(
                imgList[index]['url'],
                fit: BoxFit.fill,
              );
            },
            onIndexChanged: (index) {
              LogUtil.e(index, tag: "---------");
              valueChangeIndex = index;
              setState(() {});
            },
            itemCount: imgList.length,
            pagination: new SwiperPagination(),
            // 默认分页指示器
            loop: false,
            autoplay: false,
//            control: new SwiperControl(),
          ),
          Offstage(
              offstage: valueChangeIndex != 2,
              child: Align(
                alignment: Alignment(0.0, 0.7),
                child: SafeArea(
                  child: InkWell(
                    onTap: () {
                      if (SpUtil.getBool(GloabConfig.isLogin,
                          defValue: false)) {
                        Navigator.of(context).pushReplacementNamed(routeHome);
                      } else {
                        Navigator.of(context).pushReplacementNamed(routeLogin);
                      }
                    },
                    child: Container(
                      padding:
                          EdgeInsets.symmetric(horizontal: 30, vertical: 15),
                      margin: EdgeInsets.only(right: 20, bottom: 20),
                      decoration: BoxDecoration(
                        borderRadius: BorderRadius.circular(40),
                        color: Colors.black.withAlpha(100),
                      ),
                      child: Text(
                        '立即进入',
                        style: TextStyle(
                            fontSize: ScreenUtil().setSp(28),
                            color: Colors.white),
                      ),
                    ),
                  ),
                ),
              )),
        ],
      ),
    );
  }
}
